export const index = (n: number) => [...new Array(n).keys()];
/**
 * Parses a string into a number, automatically detecting the base.
 * @param n a number with a suffix of H or B to indicate hex or binary
 * @returns the parsed number or NaN if the string is not a number
 */
export function parseIntWithAutoBase(n: string) {
  if (n.endsWith('H')) return parseInt(n, 16);
  else if (n.endsWith('B')) return parseInt(n, 2);
  else return +n;
}
/**
 * Converts a number to a binary string, with padding to the specified length.
 * @param n a number to convert to a binary string
 */
export function toBinaryString(n: number, maxLength = 8) {
  return n.toString(2).padStart(maxLength, '0');
}
/**
 * Converts a number to a hex string, with padding to the specified length.
 * @param n a number to convert to a hex string
 */
export function toHexString(n: number, maxLength = 2) {
  return n.toString(16).padStart(maxLength, '0');
}
